<template>
  <div class="p-6">
    <!-- 标题与上传信息 -->
    <el-card>
      <template #header>
        <div class="flex justify-between items-center">
          <span class="text-xl font-bold">{{ detail.title }}</span>
          <el-tag type="info">由 {{ detail.uploader }} 上传</el-tag>
        </div>
      </template>

      <el-descriptions column="2" border class="mt-4">
        <el-descriptions-item label="大小">{{ detail.size }}</el-descriptions-item>
        <el-descriptions-item label="上传时间">{{ detail.uploadTime }}</el-descriptions-item>
        <el-descriptions-item label="种子类型">{{ detail.category }}</el-descriptions-item>
        <el-descriptions-item label="文件数">{{ detail.fileCount }}</el-descriptions-item>
        <el-descriptions-item label="活跃连接">{{ detail.peers }}</el-descriptions-item>
        <el-descriptions-item label="下载次数">{{ detail.downloadCount }}</el-descriptions-item>
      </el-descriptions>

      <div class="mt-6">
        <el-alert title="简介" type="info" show-icon />
        <p class="mt-2 whitespace-pre-line">{{ detail.description }}</p>
      </div>

      <div class="mt-6">
        <el-alert title="文件列表" type="success" show-icon />
        <el-table class="mt-2" :data="detail.files" border>
          <el-table-column prop="name" label="文件名" />
          <el-table-column prop="size" label="大小" width="120" />
        </el-table>
      </div>

      <div class="mt-6 text-right">
        <el-button type="primary" @click="downloadTorrent">下载种子</el-button>
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { useRoute } from 'vue-router';
// import { getSeedDetail, downloadSeed } from '@/api/torrent';

const route = useRoute();
const detail = ref({
  // id: '',
  title: '',
  size: '',
  uploader: '',
  uploadTime: '',
  category: '',
  fileCount: 0,
  peers: 0,
  downloadCount: 0,
  description: '',
  files: []
});

// 模拟数据
const mockDetail = {
  // id: 1,
  title: 'Ubuntu 22.04 镜像',
  size: '2.5 GB',
  uploader: 'admin',
  uploadTime: '2025-05-18 12:00',
  category: '操作系统',
  fileCount: 2,
  peers: 12,
  downloadCount: 104,
  description: '这是一份最新版本的 Ubuntu 系统 ISO 镜像文件。',
  files: [
    { name: 'ubuntu-22.04.iso', size: '2.5 GB' },
    { name: 'readme.txt', size: '1 KB' }
  ]
};

const fetchDetail = async () => {
  // const res = await getSeedDetail(id);
  // detail.value = res.data;
  detail.value = mockDetail; // 模拟数据
};

const downloadTorrent = () => {
  // downloadSeed(detail.value.id);
  alert('开始下载种子文件...');
};

onMounted(() => {
  const id = route.params.id;
  fetchDetail(id);
});
</script>
